//
//  MJModifyInfoTableViewCell.m
//  MJ
//
//  Created by qiaoBu on 2017/12/8.
//  Copyright © 2017年 lina. All rights reserved.
//

#import "MJModifyInfoTableViewCell.h"

@interface MJModifyInfoTableViewCell ()

@property (nonatomic, strong) UILabel *markLabel;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UIImageView *headerImageView;

@end

@implementation MJModifyInfoTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self commomInit];
    }
    return self;
}

- (void)commomInit{
    
    _markLabel = [[UILabel alloc] init];
    [self.contentView addSubview:_markLabel];
    [_markLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.contentView.mas_left).offset(20);
        make.centerX.centerY.mas_equalTo(self.contentView);
    }];
    _markLabel.textColor = RGBColor(102, 102, 102);
    _markLabel.font = [UIFont systemFontOfSize:16];
    _markLabel.textAlignment = NSTextAlignmentLeft;
    
    UIImageView *arrowImageView = [[UIImageView alloc] init];
    [self.contentView addSubview:arrowImageView];
    [arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(self.contentView.mas_right).offset(-20);
        make.centerY.mas_equalTo(self.contentView);
        make.size.mas_equalTo(CGSizeMake(10.5, 19));
    }];
    arrowImageView.image = [UIImage imageNamed:@"arrow_right"];
    
    _headerImageView = [[UIImageView alloc] init];
    [self.contentView addSubview:_headerImageView];
    [_headerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.right.mas_equalTo(arrowImageView.mas_left).offset(-45/2.0);
        make.centerY.mas_equalTo(self.contentView);
        make.size.mas_equalTo(CGSizeMake(50, 50));
    }];
    _headerImageView.hidden = YES;
    ViewBorderRadius(_headerImageView, 25.0, 0.5, RGBColor(217,217,217));
    
    _nameLabel = [[UILabel alloc] init];
    [self.contentView addSubview:_nameLabel];
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(arrowImageView.mas_left).offset(-45/2.0);
        make.centerY.mas_equalTo(self.contentView);
    }];
    _nameLabel.textColor = RGBColor(140,140,140);
    _nameLabel.font = [UIFont systemFontOfSize:16];
    _nameLabel.textAlignment = NSTextAlignmentRight;
    _nameLabel.hidden = YES;
    
    UIView *bottomLine = [[UIView alloc] init];
    [self.contentView addSubview:bottomLine];
    [bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.bottom.mas_equalTo(self.contentView);
        make.height.mas_equalTo(0.5);
    }];
    bottomLine.backgroundColor = RGBColor(229,229,229);
}

- (void)refreshCellWithTitle:(NSString *)title image:(NSString *)imageName name:(NSString *)name andIndexPath:(NSIndexPath *)indexPath{
    
    self.markLabel.text = title;
    
    if (indexPath.row==0)
    {
        _nameLabel.hidden = YES;
        _headerImageView.hidden = NO;
        
        if ([imageName hasPrefix:@"http"]) {
            
            NSURL *imageUrl = [NSURL URLWithString:imageName];
            [_headerImageView sd_setImageWithURL:imageUrl];
            
        }else{
             NSString *sex = [[NSUserDefaults standardUserDefaults] objectForKey:MJ_Sex];
            if ([sex isEqualToString:@"2"]) {
                 _headerImageView.image = [UIImage imageNamed:@"girl"];
            }else{
                
                 _headerImageView.image = [UIImage imageNamed:@"boy"];
            }
        }
    }
    else
    {
        _nameLabel.hidden = NO;
        _headerImageView.hidden = YES;
        if (name.length !=0) {
            
             _nameLabel.text = [NSString stringWithFormat:@"%@",name];
        }else{
            
             _nameLabel.text = @"神秘人";
        }
       
    }
}

@end
